package GroupWare;

import java.net.InetAddress;

import XML.XML;

/**
 * 连接种子类
 * 
 * @author Administrator
 * 
 */
public class Pip {
	private long gcode;
	private long gucode;
	private String userid; // 用户标识
	private InetAddress address; // 地址
	private int port; // 端口
	private XML data; // 附加信息

	public Pip() {

	}

public Pip(InetAddress ia, int port2) {
		this.address = ia;
		this.port = port2;
	}

	//	public Pip(String userID, InetAddress address, int port, XML data) {
//		super();
//		userid = userID;
//		this.address = address;
//		this.port = port;
//		this.data = data;
//	}
	public Pip(long gcode, long gucode, String userID, InetAddress address, int port) {
		super();
		this.gcode = gcode;
		this.gucode = gucode;
		this.userid = userID;
		this.address = address;
		this.port = port;
	}

	public boolean equals(Pip p) {
		return userid.equals(p.getUserID()) && gcode == p.gcode && gucode == p.gucode;
	}

	public InetAddress getAddress() {
		return address;
	}

	public XML getData() {
		return data;
	}

	public long getGcode() {
		return gcode;
	}

	public long getGucode() {
		return gucode;
	}

	public int getPort() {
		return port;
	}

	public String getUserID() {
		return userid;
	}

	public void setAddress(InetAddress address) {
		this.address = address;
	}

	public void setData(XML data) {
		this.data = data;
	}

	public void setGcode(long code) {
		this.gcode = code;
	}

	public void setGucode(long code) {
		this.gucode = code;
	}

	public void SetPip(Pip p) {
		this.setGcode(p.getGcode());
		this.setGucode(p.getGucode());
		this.setUserID(p.getUserID());
		this.setAddress(p.getAddress());
		this.setPort(p.getPort());
		this.setData(p.getData());
	}

	public void setPort(int port) {
		this.port = port;
	}

	public void setUserID(String userID) {
		userid = userID;
	}

	@Override
	public String toString() {
		if (address == null) {
			return "[Pip:userid=" + userid + "]";
		}
		return "[Pip:userid=" + userid + "\taddress=" + address.getHostAddress() + "\tport=" + port + "]";
	}
}
